/**
 * 资产配置
 */
import api from '../../../api';
import { message } from 'antd';
export default {
  namespace: 'assetAllocationCM',
  state: {},
  effects: {
    // 获取资产类别占比数据
    *queryAssetsBig({ payload, callback }, { call, put }) {
      const response = yield call(api.profitOverview.queryAssetsData, payload);
      if (response && response.code == 0) {
        callback(response.data);
      } else {
        callback();
        message.error(response && response.msg ? response.msg : '查询资产类别占比数据失败!');
        console.error(`获取资产类别占比数据失败，失败原因：${response?.msg}`, 'holdStatistics/ 接口：assetallocation/holdStatistics/');
      }
    },

    // 获取占比趋势图数据
    *queryTrendChart({ payload, callback }, { call, put }) {
      const response = yield call(api.profitOverview.queryTendencyChartData, payload);
      if (response && response.code == 0) {
        callback(response.data || {});
      } else {
        callback();
        message.error(response && response.msg ? response.msg : '查询占比趋势图数据失败!');
        console.error(`获取占比趋势图数据失败，失败原因：${response?.msg}`, 'scaleChangeTrend/ 接口：assetallocation/scaleChangeTrend/');
      }
    },

    //获取前10大重仓数据
    *queryMarkeData({ payload, callback }, { call, put }) {
      const response = yield call(api.profitOverview.queryMarkeData, payload);
      if (response && response.code == 0) {
        if (response.msg == 'Success') {
          callback(response);
        } else {
          if (response.msg == 'Success该产品穿透基本信息不全') {
            message.warning('该产品穿透基本信息不全，资产配置数据展示非穿透结果');
            callback(response);
          } else {
            message.warning(response?.msg);
            callback();
          }
        }
      } else {
        callback();
        message.error(response && response.msg ? response.msg : '查询前10大重仓数据失败!');
        console.error(`获取前10大重仓数据失败，失败原因：${response?.msg}`, 'topNHoldDetail/ 接口：assetallocation/topNHoldDetail/');
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
